<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>${not empty pmDataTree.treeName?pmDataTree.treeName:'树形字典'}管理</title>
    <meta name="decorator" content="default"/>
    <%@include file="/WEB-INF/views/include/treetable.jsp" %>
    <script type="text/javascript">
        $(document).ready(function () {
            var tpl = $("#treeTableTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g, "");
            var data = ${fns:toJson(list)};
            var rootId = "0";
            addRow("#treeTableList", tpl, data, rootId, true);
            $("#treeTable").treeTable({expandLevel: 5});
        });

        function addRow(list, tpl, data, pid, root) {
            for (var i = 0; i < data.length; i++) {
                var row = data[i];
                if ((${fns:jsGetVal('row.parentId')}) == pid) {
                    $(list).append(Mustache.render(tpl, {
                        dict: {blank123: 0}, pid: pid, row: row
                    }));
                    addRow(list, tpl, data, row.id);
                } else if ((${fns:jsGetVal('row.id')}) == pid && root) {
                    $(list).append(Mustache.render(tpl, {
                        dict: {blank123: 0}, pid: (root ? 0 : pid), row: row
                    }));
                }
            }
        }
    </script>
</head>
<body>
<ul class="nav nav-tabs">
    <li class="active"><a href="${ctx}/pm/pmDataTreeItem/listByDataTreeId?dataTreeId=${pmDataTree.id}">${not empty pmDataTree.treeName?pmDataTree.treeName:'树形字典'}列表</a></li>
    <shiro:hasPermission name="pm:pmDataTreeItem:edit">
        <li><a href="${ctx}/pm/pmDataTreeItem/form?dataTreeId=${pmDataTree.id}">${not empty pmDataTree.treeName?pmDataTree.treeName:'树形字典'}添加</a></li>
    </shiro:hasPermission>
</ul>
<sys:message content="${message}"/>
<table id="treeTable" class="table table-striped table-bordered table-condensed">
    <thead>
    <tr>
        <th>名称</th>
        <c:if test="${'Y' == pmDataTree.extAttr1List}">
            <th>${pmDataTree.extAttr1Name}</th>
        </c:if>
        <c:if test="${'Y' == pmDataTree.extAttr2List}">
            <th>${pmDataTree.extAttr2Name}</th>
        </c:if>
        <c:if test="${'Y' == pmDataTree.extAttr3List}">
            <th>${pmDataTree.extAttr3Name}</th>
        </c:if>
        <c:if test="${'Y' == pmDataTree.extAttr4List}">
            <th>${pmDataTree.extAttr4Name}</th>
        </c:if>
        <c:if test="${'Y' == pmDataTree.extAttr5List}">
            <th>${pmDataTree.extAttr5Name}</th>
        </c:if>
        <c:if test="${'Y' == pmDataTree.extAttr6List}">
            <th>${pmDataTree.extAttr6Name}</th>
        </c:if>
        <c:if test="${'Y' == pmDataTree.extAttr7List}">
            <th>${pmDataTree.extAttr7Name}</th>
        </c:if>
        <th>排序</th>
        <th>备注</th>
        <shiro:hasPermission name="pm:pmDataTreeItem:edit">
            <th>操作</th>
        </shiro:hasPermission></tr>
    </thead>
    <tbody id="treeTableList"></tbody>
</table>
<script type="text/template" id="treeTableTpl">
    <tr id="{{row.id}}" pId="{{pid}}">
        <td>{{row.name}}</td>
        <c:if test="${'Y' == pmDataTree.extAttr1List}">
            <td>{{row.extAttr1}}</td>
        </c:if>
        <c:if test="${'Y' == pmDataTree.extAttr2List}">
            <td>{{row.extAttr2}}</td>
        </c:if>
        <c:if test="${'Y' == pmDataTree.extAttr3List}">
            <td>{{row.extAttr3}}</td>
        </c:if>
        <c:if test="${'Y' == pmDataTree.extAttr4List}">
            <td>{{row.extAttr4}}</td>
        </c:if>
        <c:if test="${'Y' == pmDataTree.extAttr5List}">
            <td>{{row.extAttr5}}</td>
        </c:if>
        <c:if test="${'Y' == pmDataTree.extAttr6List}">
            <td>{{row.extAttr6}}</td>
        </c:if>
        <c:if test="${'Y' == pmDataTree.extAttr7List}">
            <td>{{row.extAttr7}}</td>
        </c:if>
        <td>{{row.sort}}</td>
        <td>{{row.remarks}}</td>
        <shiro:hasPermission name="pm:pmDataTreeItem:edit">
            <td>
                <a href="${ctx}/pm/pmDataTreeItem/form?id={{row.id}}">修改</a>
                <c:if test="${pmDataTree.maxLevel <= '1'}">
                    <a href="${ctx}/pm/pmDataTreeItem/delete?id={{row.id}}" onclick="return confirmx('确定要删除该${not empty pmDataTree.treeName?pmDataTree.treeName:'条目'}吗？', this.href)">删除</a>
                </c:if>
                <c:if test="${pmDataTree.maxLevel > '1'}">
                    <a href="${ctx}/pm/pmDataTreeItem/delete?id={{row.id}}" onclick="return confirmx('确定要删除该${not empty pmDataTree.treeName?pmDataTree.treeName:'条目'}及所有子${not empty pmDataTree.treeName?pmDataTree.treeName:'条目'}吗？', this.href)">删除</a>
                    <a href="${ctx}/pm/pmDataTreeItem/form?dataTreeId=${pmDataTree.id}&parentId={{row.id}}">添加下级${not empty pmDataTree.treeName?pmDataTree.treeName:'条目'}</a>
                </c:if>
            </td>
        </shiro:hasPermission>
    </tr>
</script>
</body>
</html>